package org.dairy.farms.dao.hibernate;

import org.dairy.farms.dao.ExpenseTypeDAO;
import org.dairy.farms.dao.generic.AbstractDAOImpl;
import org.dairy.farms.model.ExpenseType;
import org.dairy.farms.model.LivestockExpense;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: gduggira
 * Date: Jun 13, 2011
 * Time: 3:21:39 PM
 */
@Repository("expenseTypeDao")
public class ExpenseTypeDAOImpl extends AbstractDAOImpl<ExpenseType, Long> implements ExpenseTypeDAO {
    @Override
    public List<ExpenseType> loadAll() {
        return basePersistence.loadAll(ExpenseType.class);
    }

    @Override
    public ExpenseType findByName(String expenseTypeName) {
        List<ExpenseType> expenseTypeList = basePersistence.findByProperty(ExpenseType.class,"name",expenseTypeName);
        if(expenseTypeList != null && expenseTypeList.size()>=1){
            return expenseTypeList.get(0);
        }
        return null;
    }
}
